package com.quanyan.place.web;

import com.quanyan.api.APIResponse;
import com.quanyan.place.entity.ReqAdminUserVo;
import com.quanyan.place.entity.apireq.ReqBusinessAwardVo;
import com.quanyan.place.service.BusinessAwardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * Created by zhaohui on 2016/6/29.
 * 商务奖金模块
 */
@RestController
@RequestMapping("/admin/api/place/business/award")
public class BusinessAwardController {

    @Autowired
    BusinessAwardService businessAwardService;

    /**
     * 获取奖金系数
     * @param reqBusinessAwardVo
     * @param bindingResult
     * @return
     */
    @RequestMapping(value = "/getBusinessRewardRuleByCondition" ,method = RequestMethod.POST,produces = {"application/json; charset=UTF-8"})
    @ResponseBody
    public APIResponse getBusinessRewardRuleByCondition(@RequestBody @Valid ReqBusinessAwardVo reqBusinessAwardVo,BindingResult bindingResult){
        return APIResponse.returnSuccess(businessAwardService.getRewardRuleByCondition(reqBusinessAwardVo));
    }

    /**
     * 根据条件更新奖金系数及参数
     * @param reqBusinessAwardVo
     * @param bindingResult
     * @return
     */
    @RequestMapping(value = "/updateRewardRuleCondition" ,method = RequestMethod.POST,produces = {"application/json; charset=UTF-8"})
    @ResponseBody
    public APIResponse updateRewardRuleCondition(@RequestBody @Valid ReqBusinessAwardVo reqBusinessAwardVo,BindingResult bindingResult){
        return APIResponse.returnSuccess(businessAwardService.updateRewardRuleCondition(reqBusinessAwardVo));
    }


    /**
     * 商务代表list
     * @param reqBusinessAwardVo
     * @param bindingResult
     * @return
     */
    @RequestMapping(value = "/getBusinessAwardCondition" ,method = RequestMethod.POST,produces = {"application/json; charset=UTF-8"})
    @ResponseBody
    public APIResponse getBusinessAwardCondition(@RequestBody @Valid ReqBusinessAwardVo reqBusinessAwardVo,BindingResult bindingResult){
        return APIResponse.returnSuccess(businessAwardService.getBusinessAgentAward(reqBusinessAwardVo));
    }

    /**
     * 商务主管
     * @param reqBusinessAwardVo
     * @param bindingResult
     * @return
     */
    @RequestMapping(value = "/getBusinessManagerAwardCondition" ,method = RequestMethod.POST,produces = {"application/json; charset=UTF-8"})
    @ResponseBody
    public APIResponse getBusinessManagerAwardCondition(@RequestBody @Valid ReqBusinessAwardVo reqBusinessAwardVo,BindingResult bindingResult){
        return APIResponse.returnSuccess(businessAwardService.getBusinessManagerAward(reqBusinessAwardVo));
    }

    /**
     * 城市经理
     * @param reqBusinessAwardVo
     * @param bindingResult
     * @return
     */
    @RequestMapping(value = "/getBusinessCityManagerCondition" ,method = RequestMethod.POST,produces = {"application/json; charset=UTF-8"})
    @ResponseBody
    public APIResponse getBusinessCityManagerCondition(@RequestBody @Valid ReqBusinessAwardVo reqBusinessAwardVo,BindingResult bindingResult){
        return APIResponse.returnSuccess(businessAwardService.getBusinessCityManagerAward(reqBusinessAwardVo));
    }


    /**
     * 用户底薪列表
     * @param reqBusinessAwardVo
     * @param bindingResult
     * @return
     */
    @RequestMapping(value = "/getTbBizPlaceEmployee" ,method = RequestMethod.POST,produces = {"application/json; charset=UTF-8"})
    @ResponseBody
    public APIResponse getTbBizPlaceEmployee(@RequestBody @Valid ReqBusinessAwardVo reqBusinessAwardVo,BindingResult bindingResult){
        return APIResponse.returnSuccess(businessAwardService.getTbBizPlaceEmployee(reqBusinessAwardVo));
    }

    /**
     * 设置用户底薪
     * @param reqBusinessAwardVo
     * @param bindingResult
     * @return
     */
    @RequestMapping(value = "/updateBatchUserSalary" ,method = RequestMethod.POST,produces = {"application/json; charset=UTF-8"})
    @ResponseBody
    public APIResponse updateBatchUserSalary(@RequestBody @Valid ReqBusinessAwardVo reqBusinessAwardVo,BindingResult bindingResult){
        return APIResponse.returnSuccess(businessAwardService.updateBatchUserSalary(reqBusinessAwardVo));
    }

    /**
     * 手动调用指标统计定时任务
     * @return
     */
    @RequestMapping(value = "/timedTask" ,method = RequestMethod.GET)
    @ResponseBody
    public APIResponse timedTask(){
        businessAwardService.insertAgentStatis();
        return APIResponse.returnSuccess();
    }

    /**
     * 手动调用奖金统计定时任务
     * @return
     */
    @RequestMapping(value = "/timedTask1" ,method = RequestMethod.GET)
    @ResponseBody
    public APIResponse timedTask1(){
        businessAwardService.insertCityManagerAward();
        return APIResponse.returnSuccess();
    }
}
